package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhentao.model.dto.product.BrandDto;
import com.zhentao.model.entity.product.Brand;
import com.zhentao.model.vo.common.Result;
import com.zhentao.model.vo.common.ResultCodeEnum;
import com.zhentao.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


//品牌管理
@RestController
@RequestMapping("/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    //查询所有品牌
    @PostMapping(value = "/list")
    public Result list(@RequestBody BrandDto brandDto){
        Result brandlist = brandService.brandlist(brandDto);
        return brandlist;
    }

    //上传图片,将图片路径保存到minio中
    @PostMapping(value = "/file")
    public Result file(MultipartFile file) throws IOException {
        Result file1 = brandService.file(file);
        return file1;
    }

    //添加品牌信息
    @PostMapping(value = "/save")
    public Result save(@RequestBody Brand brand){
        return Result.build(brandService.brandsave(brand), ResultCodeEnum.SUCCESS);
    }

    //修改品牌信息
    @PostMapping(value = "/update")
    public Result update(@RequestBody Brand brand){
        return Result.build(brandService.brandupdadte(brand), ResultCodeEnum.SUCCESS);
    }

    //删除品牌信息
    @PostMapping(value = "/delete")
    public Result delete(@RequestParam Long id){
        Result branddelete = brandService.branddlete(id);
        return branddelete;
    }

    @PostMapping(value = "BrandFindAll")
    public Result BrandFindAll(){
        LambdaQueryWrapper<Brand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(true,Brand::getIsDeleted,0);
        List<Brand> brands = brandService.list(wrapper);
        return Result.build(brands, ResultCodeEnum.SUCCESS);
    }

}
